package shizhan.proxy;

//import net.sf.cglib.proxy.InvocationHandler;
import org.apache.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class CalculatorJDK implements InvocationHandler {
    Logger logger = Logger.getLogger(CalculatorJDK.class);

    private Object target;
    private String methodName;  // 用的 运算类型

    public CalculatorJDK(Object target, String methodName) {
        this.target = target;
        this.methodName = methodName;
    }


    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

       logger.info("开始使用" + methodName + "运算");

        double object =(Double) method.invoke(target, objects);


        logger.info(methodName + "运算完成，结果：" + object);

        return object;
    }
}
